<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="${package}mapper.${pojo_name_mapper}">
    <resultMap type="${package}pojo.${pojo_name}" id="BaseResultMap">
        <#if COLUMNS?exists>
        <#list COLUMNS as model>
        <#if model.isPK == "true">
        <id column="${model.columnName}" jdbcType="${model.columnType}" property="${model.javaName}" />
        <#else>
        <result column="${model.columnName}" jdbcType="${model.columnType}" property="${model.javaName}"    />
        </#if>
        </#list>
        </#if>
    </resultMap>

    <sql id="Base_Column_List">
        <#list COLUMNS as model>
        <#if model_has_next>
        ${model.columnName},
        <#else>
        ${model.columnName}
        </#if>
        </#list>
    </sql>

<#--    <insert id="insert" useGeneratedKeys="true" keyColumn="id" keyProperty="id" parameterType="${package}pojo.${pojo_name}">-->
    <insert id="insert" useGeneratedKeys="true" keyColumn="id" keyProperty="id" >
        INSERT INTO ${table_name}
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <#if COLUMNS?exists>
            <#list COLUMNS as model>
            <#if model_has_next>
            <#if model.type == "str">
                <if test="null != ${model.javaName} and '' != ${model.javaName}">
                    ${model.columnName},
                </if>
            <#else>
                 <#if model.isPK != "true">
                <if test="null != ${model.javaName} ">
                    ${model.columnName},
                </if>
                 </#if>
            </#if>
            <#else>
            <#if model.type == "str">
                <if test="null != ${model.javaName} and '' != ${model.javaName}">
                    ${model.columnName}
                </if>
            <#else>
                <#if model.isPK != "true">
                <if test="null != ${model.javaName} ">
                    ${model.columnName}
                </if>
                </#if>
            </#if>
            </#if>
            </#list>
            </#if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <#if COLUMNS?exists>
            <#list COLUMNS as model>
            <#if model_has_next>
            <#if model.type == "str">
                <if test="null != ${model.javaName} and '' != ${model.javaName}">
                    ${r'#{'} ${model.javaName} ${r'}'},
                </if>
            <#else>
                <#if model.isPK != "true">
                <if test="null != ${model.javaName} ">
                    ${r'#{'} ${model.javaName} ${r'}'},
                </if>
                </#if>
            </#if>
            <#else>
            <#if model.type == "str">
                <if test="null != ${model.javaName} and '' != ${model.javaName}">
                    ${r'#{'} ${model.javaName} ${r'}'}
                </if>
            <#else>
                <#if model.isPK != "true">
                <if test="null != ${model.javaName} ">
                    ${r'#{'} ${model.javaName} ${r'}'}
                </if>
                </#if>
            </#if>
            </#if>
            </#list>
            </#if>
        </trim>
    </insert>

    <delete id="delete" >
        DELETE FROM ${table_name}
        <#if COLUMNS?exists>
        <#list COLUMNS as model>
        <#if model.isPK == "true">
        WHERE    ${model.columnName}=${r'#{'} ${model.javaName} ${r'}'}
        </#if>
        </#list>
        </#if>
    </delete>

    <delete id="batchDelete" >
        DELETE FROM ${table_name}
<#if COLUMNS?exists>
<#list COLUMNS as model>
    <#if model.isPK == "true">
        WHERE    ${model.columnName} in
        <foreach item="id" collection="list" separator="," open="(" close=")" index="">
            ${r'#{id}'}
        </foreach>
    </#if>
</#list>
</#if>
    </delete>

<#--    <update id="update" parameterType="${package}pojo.${pojo_name}">-->
    <update id="update" >
        UPDATE ${table_name}
        <set>
            <#if COLUMNS?exists>
            <#list COLUMNS as model>
            <#if model_has_next>
            <#if model.type == "str">
                <if test="null != ${model.javaName} and '' != ${model.javaName}">${model.columnName} = ${r'#{'} ${model.javaName} ${r'}'},</if>
            <#else>
                <#if model.isPK != "true">
                <if test="null != ${model.javaName} ">${model.columnName} = ${r'#{'} ${model.javaName} ${r'}'},</if>
                </#if>
            </#if>
            <#else>
            <#if model.type == "str">
                <if test="null != ${model.javaName} and '' != ${model.javaName}">${model.columnName} = ${r'#{'} ${model.javaName} ${r'}'}</if>
            <#else>
                <#if model.isPK != "true">
                <if test="null != ${model.javaName} ">${model.columnName} = ${r'#{'} ${model.javaName} ${r'}'}</if>
                </#if>
            </#if>
            </#if>
            </#list>
            </set>
            <#list COLUMNS as model>
            <#if model.isPK == "true">
            WHERE    ${model.columnName}=${r'#{'} ${model.javaName} ${r'}'}
            </#if>
            </#list>
            </#if>
    </update>


    <select id="details" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List" />
        FROM  ${table_name}
        <#if COLUMNS?exists>
        <#list COLUMNS as model>
        <#if model.isPK == "true">
        WHERE    ${model.columnName}=${r'#{'} ${model.javaName} ${r'}'}
        </#if>
        </#list>
        </#if>
    </select>

<#--    <select id="pageList" parameterType="${package}pojo.${pojo_name}" resultMap="BaseResultMap">-->
    <select id="pageList"  resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List" />
        FROM ${table_name}
<#if COLUMNS?exists>
    WHERE 1= 1
<#list COLUMNS as model>
<#if model.javaType == "String">
    <if test="null != exclude${model.javaName ? cap_first} and exclude${model.javaName ? cap_first}.size() > 0">
        and ${model.columnName} not in
        <foreach item="exclude${model.javaName ? cap_first}By" collection="exclude${model.javaName ? cap_first}" separator="," open="(" close=")" index="">
            ${r'#{'} exclude${model.javaName ? cap_first }By ${r'}'}
        </foreach>
    </if>
</#if>
<#if model.javaType == "String">
    <if test="null != ${model.javaName } and ${model.javaName}.size() > 0">
        and ${model.columnName} in
        <foreach item="${model.javaName }By" collection="${model.javaName}" separator="," open="(" close=")" index="">
            ${r'#{'} ${model.javaName }By ${r'}'}
        </foreach>
    </if>
</#if>
</#list>
</#if>
<#if COLUMNS?exists>
<#list COLUMNS as model>
    <#if model.isPK == "true">
        order by ${model.columnName} DESC
    </#if>
</#list>
</#if>
    </select>

<#--    <select id="countAll" resultType="java.lang.Integer">-->
<#--        SELECT count(1)-->
<#--        FROM dsg_data_partner_personnel_audit-->
<#--    </select>-->
</mapper>